package com.itheima02.day06test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author 刘全
 * @date 2021/7/22
 */
//4. 用两种方式实现：键盘录你的入生日 (xxxx-xx-xx)  计算你活了多少天？
public class Test4 {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        while (true) try {
            System.out.println("请输入您的生日(xxxx-xx-xx):");
            String s = sc.nextLine();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date d1 = sdf.parse(s);
            Date d2 = new Date();
            long bir = d1.getTime();
            long now = d2.getTime();
            System.out.println("你已经活了" + (now - bir) / 1000 / 24 / 3600 + "天了,希望你能长命百岁");
            break;
        } catch (ParseException e) {
            System.out.println("您输入的格式有误,请按照括号内的格式输入");
        }
    }
}
